package interview.tree;

public class TreeNode
{
	private final char value;
	private TreeNode left;
	private TreeNode right;
	private TreeNode parent;

	public TreeNode(char value)
	{
		this.value = value;
		this.left = null;
		this.right = null;
		this.parent = null;
	}

	public TreeNode getLeft()
	{
		return left;
	}

	public void setLeft(TreeNode left)
	{
		this.left = left;// 当我设置它左结点的时候
		if (this.left != null)
		{
			this.left.setParent(this);// 就能知道它的左结点的父亲就是它自己
		}
	}

	public TreeNode getRight()
	{
		return right;
	}

	public void setRight(TreeNode right)
	{
		this.right = right;
		if (this.right != null)
		{
			this.right.setParent(this);
		}
	}

	public char getValue()
	{
		return value;
	}

	public TreeNode getParent()
	{
		return parent;
	}

	private void setParent(TreeNode parent)// 防止乱指
	{
		this.parent = parent;
	}

}
